package bairui.international.weixin.portal.miniapp.controller.spread.img;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_SpreadImage;
import bairui.international.model.type.Type_SpreadImage;
import bairui.international.service.Service_SpreadImage;
import lombok.Getter;

/**
 *
 * 获取
 *
 * @generated
 * 
 * @see STest_C_Spread_Img_Get_Get 测试
 *
 */
@Controller
public class C_Spread_Img_Get_Get
 extends SC_Spread_Img_Get_Get 
{
	
	@Autowired private Service_SpreadImage service_SpreadImage;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request, 
		@RequestParam Type_SpreadImage type
	) throws Exception {
		return new Output(
				service_SpreadImage.findFirst(it->it.imgType.eq(type), it->new QSort(it.orderValue.desc()))
			);
	}
	
	public static class Output {
		private @Getter long id;
		private @Getter String imgUrl;
		public Output(TB_SpreadImage bean) {
			if(null == bean){
				return;
			}
			this.id = bean.getId();
			this.imgUrl = C_Spread_Img_Show_ShowImg.ShowImg.Operate(bean.getId()).getUrl();
		}
	}

}
